package com.itchu.system.controller;

import com.itchu.common.domain.PageResult;
import com.itchu.system.domain.Song;
import com.itchu.system.service.CheckService;
import com.itchu.system.service.SongService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 这里的控制器全部都是后台系统的，需要认证才可以访问的
 */

@RestController
@RequestMapping("/check")
public class CheckController {

    @Autowired
    private CheckService checkService;

    /**
     * ----------------------
     * 查找歌曲的分页信息
     * @param key   搜索条件
     * @param page  当前页
     * @param state  审核状态码
     * @param rows  页大小
     * @return
     */
    @GetMapping("page")
    public ResponseEntity<PageResult<Song>> showAll(
            @RequestParam(value = "key",required = false) String key,
            @RequestParam(value = "page" , defaultValue = "1") Integer page,
            @RequestParam(value = "rows", defaultValue = "5") Integer rows,
            @RequestParam(value = "state") Integer state
    ) {
        PageResult<Song> list = checkService.showAll(key, page, rows,state);
        return ResponseEntity.ok(list);
    }

    /**
     * 审核的操作，0代表通过，2代表不通过
     * @param songId
     * @param state
     * @return
     */
    @PostMapping("/changeState")
    public ResponseEntity<Void> changeState(
            @RequestParam("songId") Long songId,
            @RequestParam("state") Integer state
    ) {
        checkService.changeState(songId,state);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }
}
